package com.cjl.jvm.up;

public class VolatileImprove {

    public static void main(String[] args) {

        A aInstance = new A();

        for (int i = 0; i < 5; i++) {
            MyThread myThread1 = new MyThread("threadAAA",aInstance);
            MyThread myThread2 = new MyThread("threadBBB",aInstance);
            myThread2.start();
            myThread1.start();
        }



    }

    public static class MyThread extends Thread{
        A a;
        String name;

        MyThread(String name,A a){
            super(name);
            this.name = name;
            this.a = a;
        }

        @Override
        public void run() {
            super.run();
            try {
                if ("threadAAA".equals(name)){
                    a.inA();
                }else {
                    a.inB();
                }
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


}
